package cn.edu.scau.cmi.mazhuanglong.comprehensive;

import java.awt.Component;

import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.*;
import javax.swing.table.TableColumn;
import java.awt.*;
public class MyCellEditor extends DefaultCellEditor {

	public MyCellEditor(JCheckBox checkBox) {
		super(checkBox);
	}

	public MyCellEditor(JComboBox comboBox) {
		super(comboBox);
	}

	public MyCellEditor(JTextField textField) {
		super(textField);
	}

	@Override
	public boolean stopCellEditing() {
		Component comp=getComponent();
		
		Object obj1=getCellEditorValue();
		if(obj1==null||(!obj1.toString().matches("^100$|^(\\d|[1-9]\\d)$"))) {
			comp.setForeground(Color.RED);
			return false;
		}
		
		// 数据合法时，设置编辑器组件内的内容颜色为黑色
        comp.setForeground(Color.BLACK);
        
		return super.stopCellEditing();

	}
}
